<template>
  <a-row type="flex">
    <a-col :flex="toggle ? '260px' : '30px'" style="margin-right: 12px; background-color: #fff">
      <depart-tree :departType="2" :rootOpened="true" :multi="false" @ok="getTreeData" @toggleBool="toggleBool" />
    </a-col>
    <a-col flex="auto">
      <a-card :bordered="false" style="margin-bottom: 10px">
        <!-- 查询区域 -->
        <a-form-model :label-col="labelCol" :wrapper-col="wrapperCol" @keyup.enter.native="onQuery">
          <a-row>
            <a-col :span="6">
              <a-form-model-item label="考核对象">
                <a-input v-model="queryParam.assessUser" placeholder="请输入" />
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="是否完成初始化">
                <a-select v-model="queryParam.isInitialization" placeholder="请选择" style="width:100%;" allowClear>
                  <a-select-option v-for="(item, key) in judgment" :key="key" :value="item.value">{{ item.title }}
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :span="4">
              <a-form-model-item :wrapper-col="{ offset: 0 }" style="margin-bottom: 0">
                <a-button type="primary" @click="onQuery"> 查询 </a-button>
                <a-button style="margin-left: 10px" @click="onResetForm"> 重置 </a-button>
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </a-card>
      <a-card>
        <div class="table-page-content">
          <z-table ref="table" rowKey="id" :showAlert="false" :showSelection="true" :loading="loading"
                   :columns="columns" :dataSource="pageData" @selectedRow="onSelectedRow" @change="onTableChange">
            <!--操作-->
            <template slot="action" slot-scope="text, record">
              <a-button type="link" style="padding: 0" @click.stop="onDetail(record)">详情</a-button>
            </template>
          </z-table>
        </div>
      </a-card>
    </a-col>
  </a-row>


</template>

<script>
  import { getDictItemsFromCache } from '@/api/api'
  import Api from '@/api/sjsk/performanceServiceQuery'
  import DepartTree from '@/views/sjsk/modules/departTree'

  export default {
    name: "selfExamine",
    components: {
      DepartTree
    },
    data() {
      return {
        labelCol: { span: 6 },
        wrapperCol: { span: 17 },
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: 'order',
            width: 60,
            align: 'center',
            customRender: (text, record, index) =>
              `${(this.pageFilter.pageNo - 1) * this.pageFilter.pageSize + (index + 1)}` //序号分页后连续
          },
          {
            title: '考核对象',
            align: "center",
            dataIndex: 'assessUser'
          },
          {
            title: '是否完成初始化',
            align: "center",
            dataIndex: 'isInitialization',
          },
          {
            title: '初始化时间',
            align: "center",
            dataIndex: 'initializationTime'
          },
          {
            title: '考核得分',
            align: "center",
            dataIndex: 'assessScore'
          },
          {
            title: '考核建议',
            align: 'center',
            dataIndex: 'assessProposal'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: "center",
            scopedSlots: {customRender: 'action'},
          }
        ],
        judgment: getDictItemsFromCache('judgment'),
        loading: false,
        pageFilter: {
          pageNo: 1,
          pageSize: 10,
        },
        queryParam:{},
        pageData: {},
        toggle:true,
        checkList:[]
      }
    },
    created(){
      this.componentName = this.$route.meta.componentName
      this.onQuery()
    },
    methods: {
      // 查询
      onQuery() {
        this.pageFilter.pageNo = 1
        this.refreshTable()
      },
      // 重置
      onResetForm() {
        this.queryParam = {}
        this.pageFilter = {
          pageNo: 1,
          pageSize: 10
        }
        this.refreshTable()
      },
      onSelectedRow(keys) {
        this.checkList = keys;
      },
      onTableChange(pagination, pageFilter, sorter) {
        let keyMap = { currentPage: 'pageNo' }
        let paginations = Object.keys(pagination).reduce((newData, key) => {
          let newKey = keyMap[key] || key
          newData[newKey] = pagination[key]
          return newData
        }, {})
        this.pageFilter = Object.assign({}, this.pageFilter, paginations)
        this.refreshTable()
      },
      refreshTable() {
        this.loading = true
        this.queryParam.id = this.$route.query.id;
        let params = Object.assign({}, this.queryParam, this.pageFilter)
        let interfaceMethod = Api.selfEvaluationDetail(params)
        interfaceMethod.then((res) => {
          if (res.success) {
            this.pageData = res.result ? res.result : {}
            this.loading = false
            this.$refs.table.onClearRowKeys()
          } else {
            this.loading = false
            this.pageData = {}
            this.$message.warn('请求失败！')
          }
        }).catch((e) => {
          this.loading = false
          this.$message.warn('请求失败！')
        })
      },
      onDetail(record) {
        this.$router.push({
          path: '/executeExamine/bgtDetails',
          query: {
            id: record.id,
            type:'executeExamine'
          },
        })
      },
      // 选中组织架构树，赋值到人员列表搜索框
      getTreeData(datas, id) {
        console.log(datas, id)
        this.$set(this.pageFilter, 'assessUser', id)
      },
      toggleBool(bool) {
        console.log(bool)
        this.toggle = bool
      }
    }
  }
</script>
<style lang="less" scoped>

</style>